<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">
		<!--App自定义的css-->
		<link rel="stylesheet" type="text/css" href="../css/app.css" />
		<style type="text/css">
			.message {
				background-color: #fff;
				z-index: 99;
				box-shadow: 0px -5px 5px 0px rgba(150, 150, 150, .2);
			}
			
			.message.bottom {
				position: fixed;
				padding: 5px;
				bottom: 0;
				left: 0px;
				right: 0px;
			}
			.message.top {
				position: fixed;
				padding: 5px;
				top: 0;
				left: 0px;
				right: 0px;
			}
			
			.radio_inline{  
				display: inline-block;  
				width: 65%;  
			}  
			.radio_inline label{  
				width: 15%;  
				padding-left: 40px;  
				padding-right: 40px;  
			}  
			.radio_inline input[type=radio]{  
				width: 15%;               
				right: auto;  
			}  
			
		</style>
	</head>

	<body class="body-class">
		<div class="message top">
			<div class="mui-input-row  " style="width:100%">
						   <label  >性别</label>  
							<span class="radio_inline mui-radio">  
								<input name="fenlei" type="radio" id="radio_man" checked value="1">  
								<label for="radio_man">库存</label>  
								<input name="fenlei" type="radio" id="radio_woman" value="0">         
								<label for="radio_woman">订单</label>        
							</span>  
					 </div>
			<input id="boxCodeInput" type="text" class="mui-input-clear" placeholder="托盘条码">
			<input id="barCodeInput" type="text" class="mui-input-clear" placeholder="箱条码">	 
		</div>
		<div  style="height:10rem" >
			  
		</div>
		<div class="mui-content" id="mui-content-id">
		</div>
		<div style="height:5rem" />
		<div class="message bottom">
			<button id="saveButton" type="button" class="mui-btn mui-btn-block mui-btn-primary">保存</button>
		</div>
		<script src="../js/mui.js"></script>
	</body>
<script type="text/javascript" charset="utf-8">
	 document.getElementById('saveButton').addEventListener('tap', function() {
		var boxCode = document.getElementById('boxCodeInput').value
		if (!boxCode) {
			mui.toast("请输入托盘条码")
			document.getElementById("boxCodeInput").focus();
			return;
		}
		var list =document.querySelectorAll('.mui-card');
		var arr = new Array();
		 
		for (var i = 0; i < list.length; i++) {
			var node=list[i];
			var det={barCode:node.children[0].children[0].innerHTML,countDb:node.children[1].innerHTML};
			if(!det.countDb ){
				mui.toast(det.barCode+'请输入数量？');
				return;
			}
			arr.push(det)
		}
	 
		mui.post("/CoreStock/SaveStock", {detailList:arr,stock:{boxCode:boxCode}}, function(response) {
			if (response.data != "ok") {
				mui.confirm(response.data)
			} else {
				alert('保存成功')
				window.location.reload();
			}
	 
		}, "json");
	 }, false);
	 
	 function addDetail( va,count){
		 var list = document.querySelectorAll('.mui-card');
		 for (var i = 0; i < list.length; i++) {
			if (list[i].children[0].innerHTML == va) {
				this.value = ""
				return;
			}
		 }
		 var data = '<div class="mui-card-content mui-card-content-inner"><div style="display:inline;">'+va+'</div><span class="mui-icon mui-icon-eye" style="display:inline;float:right" /></div><div class="mui-card-footer">'+count+'</div>'
		 var div = document.createElement('div');
		 div.className = "mui-card";
		 div.innerHTML = data
		 var content = document.body.querySelector('#mui-content-id');
		 content.appendChild(div)
	 }

	(function($) {
		document.getElementById("boxCodeInput").addEventListener('input', function(event) {
			if(this.value.length>6){
				mui.getJSON("/pda/getStock/"+boxCode, {}, function(response) {
					if (response.data != "ok") {
						mui.confirm(response.data)
						retun;
					} 
					var list= response.data.detList;
					for(var i=0;i<list.length;i++){
						addDetail( list[i].barCode,list[i].countDb)
					}
					
							 
				}, "json");
				mui.toast(this.value);
				document.getElementById("barCodeInput").value = "";
				document.getElementById("barCodeInput").focus();
			} 
		}, false);
		document.getElementById("barCodeInput").addEventListener('input', function(event) {
			if (this.value.length >= 12) { 
				var va = this.value;
				 addDetail( va,0)
				this.value = ""
			}
		}, false);
		var btnArray = ['确认', '取消'];
		$('#mui-content-id').on('swiperight', '.mui-card', function(event) {
			var elem = this;
			mui.confirm('确认删除该条记录？', 'Hello MUI', btnArray, function(e) {
				if (e.index == 0) {
					elem.parentNode.removeChild(elem);
				} else {
					setTimeout(function() {
						$.swipeoutClose(elem);
					}, 0);
				}
			});
		});
		
		var tapCard=""
		$('#mui-content-id').on('tap', '.mui-card', function(event) {
			tapCard=this;
			mui.prompt("", '数量', this.children[0].children[0].innerHTML, btnArray, function(e) {
				if (e.index == 0) {
					tapCard.children[1].innerHTML= e.value;
				} 
			})
			 
		});
	})(mui);
</script>
</html>